/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package univalle.eisc.pais.ai.searcheslab.model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 *
 * @author victor
 */
public class Config {

    private int N;
    private int weightObject1;
    private int weightObject2;
    private int[][] struct;

    public Config() {
        N = 0;
        weightObject1 = 0;
        weightObject2 = 0;
        struct = new int[0][0];
    }

    public void loadConfig(File file) throws Exception {
        if (file.exists()) {
            FileReader reader = new FileReader(file);
            BufferedReader buffReader = new BufferedReader(reader);
            String s = buffReader.readLine();
            String[] cont = s.split(" ");

                N = Integer.parseInt(cont[0]);
                weightObject1 = Integer.parseInt(cont[1]);
                weightObject2 = Integer.parseInt(cont[2]);
                struct = new int[N][N];

                int row = 0;
                while ((s = buffReader.readLine()) != null) {
                    cont = s.split(" ");
                    if (cont.length != N) {
                        throw new Exception(
                                "La fila [" + row + "] debe contener " + N + " elementos");
                    }
                    int col = 0;
                    for (String value : cont) {
                        struct[row][col] = Integer.parseInt(value);
                        if (struct[row][col] < -5) {
                            throw new Exception(
                                    "El dato [" + row + "][" + col + "] debe ser >= -5");
                        }
                        col++;
                    }
                    row++;
                }
        
        } else {
            throw new Exception("El archivo no existe");
        }

    }

    public int getN() {
        return N;
    }

    public void setN(int N) {
        this.N = N;
    }

    public int getWeightObject1() {
        return weightObject1;
    }

    public void setWeightObject1(int weightObject1) {
        this.weightObject1 = weightObject1;
    }

    public int getWeightObject2() {
        return weightObject2;
    }

    public void setWeightObject2(int weightObject2) {
        this.weightObject2 = weightObject2;
    }

    public int[][] getStruct() {
        return struct;
    }

    public void setStruct(int[][] struct) {
        this.struct = struct;
    }
}
